package fields;

import translate.Translate;
import gstd.Field;
import gstd.Player;
import entities.Inventory;

public abstract class Ownable extends Field {
	protected int price;
	protected Player owner;

	private boolean buyFieldDecision;

	public void setBuyFieldDecision(boolean buyFieldDecision) {
		this.buyFieldDecision = buyFieldDecision;
	}

	public Ownable(String name, int price) {
		super(name);
		this.price = price;
	}

	protected void buyField(Player player) {
		if (buyFieldDecision && this.owner == null) {
			setOwner(player);
			owner.getInventory().addBalance(-price);
			((Inventory) owner.getInventory()).addField(this);
		}
		this.buyFieldDecision = false;
	}
	
	public void setOwner(Player player) {
		this.owner = player;
	}
	
	public abstract int getRent();
	
	public Player getOwner() {
		return this.owner;
	}

	public int getPrice() {
		return price;
	}

	@Override
	public String toString() {
		return Translate.print("Price: %d ", price);
	}
}
